package zoo.member.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import zoo.member.dao.MemberDao;
import zoo.member.domain.MemberCommand;
import zoo.qboard.domain.QboardCommand;





@Controller
public class MemberUpdateController {
	private static Log log = LogFactory.getLog(MemberUpdateController.class);
	private MemberDao memberDao;
	private String formViewName = "updateMember";
	
	@Autowired
	public void setMemberDao(MemberDao memberDao){
		this.memberDao=memberDao;
	}
	@RequestMapping(value="/main/updateMember.do",method=RequestMethod.GET)
	public ModelAndView process(@RequestParam("userid") String userid) {
      	MemberCommand updatemember= null;
		updatemember = memberDao.getMember(userid);
		return new ModelAndView("updateMember", "updateMember", updatemember);
	}
	@ModelAttribute("memberCommand")
	public MemberCommand formBacking() {
		return new MemberCommand();
	}
	@RequestMapping(value="/main/updateMember.do", method=RequestMethod.POST)
	public String submit(@ModelAttribute("memberCommand") MemberCommand memberCommand, BindingResult result){

		if(result.hasErrors()){
			return formViewName;
		}
		
		System.out.println(memberCommand);
		memberDao.updateMember(memberCommand);
		
		return "redirect:/main/index.do";
	}

}
